﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace FTchina.Api
{
    /// <summary>
    ///state 的摘要说明
    /// </summary>
    public class state
    {
        public state()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }

        #region 评论相关
        /// <summary>
        /// 检查是否允许评论
        /// </summary>
        /// <param name="id">文章id</param>
        /// <returns></returns>
        public static Boolean ChkCanPinglun(string id)
        {
            //获取文章所属栏目
            string lanmuid = shujuku.GetValueByKey("lanmuid", "content", "id=" + id, "ChkCanPinglun");
            //获取栏目是否允许评论并返回
            return (shujuku.GetValueByKey("pinglun", "lanmu", "id=" + lanmuid, "ChkCanPinglun") == "1");
        }
        /// <summary>
        /// 获取评论数量
        /// </summary>
        /// <param name="id">指定文章id，为空则取所有文章的评论</param>
        /// <returns></returns>
        public static string GetCountPinglun(string id)
        {
            if (id.Length == 0)
            {
                return shujuku.GetValueByKey("count(id)", "pinglun", "1=1", "GetCountPinglun");
            }
            else
            {
                return shujuku.GetValueByKey("count(id)", "pinglun", " artid=" + id, "GetCountPinglun");
            }

        }
        #endregion

        #region 获取网站整体统计数据
        /// <summary>
        /// 文章总数
        /// </summary>
        public static string ArtCount
        {
            get
            {
                return shujuku.GetValueByKey("count(id)", "content", "1=1", "ArtCount");
            }

        }
        /// <summary>
        /// 未审核文章总数
        /// </summary>
        public static string NopassArtCount
        {
            get
            {
                return shujuku.GetValueByKey("count(id)", "content", "ispass=0", "NopassArtCount");
            }

        }
        /// <summary>
        /// 图片文章总数
        /// </summary>
        public static string ImgArtCount
        {
            get
            {
                return shujuku.GetValueByKey("count(id)", "content", "isimg=1", "ImgArtCount");
            }

        }
        /// <summary>
        /// 回收站文章总数
        /// </summary>
        public static string DelArtCount
        {
            get
            {
                return shujuku.GetValueByKey("count(id)", "content", "isdel=1", "DelArtCount");
            }
        }
        /// <summary>
        /// 文章总点击量
        /// </summary>
        public static string HitCount
        {
            get
            {
                return shujuku.GetValueByKey("sum(hit)", "content", "1=1", "HitCount");
            }
        }
        /// <summary>
        /// 文章分类总数
        /// </summary>
        public static string ColumnCount
        {
            get
            {
                return shujuku.GetValueByKey("count(id)", "lanmu", "parentid!=0", "ColumnCount");
            }
        }
        /// <summary>
        /// 留言总数
        /// </summary>
        public static string LiuyanCount
        {
            get
            {
                return shujuku.GetValueByKey("count(id)", "liuyan", "1=1", "LiuyanCount");
            }
        }
        /// <summary>
        /// 评论总数
        /// </summary>
        public static string CommentCount
        {
            get
            {
                return shujuku.GetValueByKey("count(id)", "pinglun", "1=1", "CommentCount");
            }
        }

        /// <summary>
        /// 获取指定栏目下文章数量
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static string GetCountContent(string id)
        {
            if (id == "0")
            {
                return ArtCount;
            }
            else
            {
                return shujuku.GetValueByKey("count(id)", "content", " lanmuid=" + id, "GetCountContent"+id);
            }

        }

        #endregion

        #region 系统内部使用
        public static string RootColuID
        {
            get { return shujuku.GetValueByKey("id", "lanmu", "parentid=0","rootcoluid"); }
        }
        #endregion

    }
}